import { cities, hotcities } from './city'
Page({
    data : {
      cities : [],
			hotCitis: hotcities
    },
		onLoad () {
		

		},
    onChange(event){
      // console.log(event.detail)
    },
		onClickName(e){
			let pages = getCurrentPages(); //获取当前页面js里面的pages里的所有信息。
			let prevPage = pages[pages.length - 2] // 上一页
			prevPage.setData({ 
				cityActive: e.currentTarget.dataset.name
			})
			wx.navigateBack({
				delta: 1
			})
		},
    onReady(){
        let storeCity = new Array(26);
        const words = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
        words.forEach((item,index)=>{
            storeCity[index] = {
                key : item,
                list : []
            }
        })
        cities.forEach((item)=>{
					let firstName = item.group;
					let index = words.indexOf( firstName );
					storeCity[index].list.push({
						name: item.city,
						key : firstName
					});
        })
        this.data.cities = storeCity;
        this.setData({
            cities : this.data.cities
        })
			// console.log(this.data.cities)
    }
});